/**
 * Copyright (c) 2010-2011 julewa.com.  
 * All rights reserved. 
 * 
 * @author Huang Benhua
 * @date 2011-2-20
 * 
**/
package com.julewa.db.ibatis;

import java.util.Map;
import java.util.Properties;

import org.springframework.beans.factory.annotation.Autowired;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.julewa.db.BeanInfo;
import com.julewa.db.ibatis.loading.IbatisLoader;
import com.julewa.loading.TextsImpl;
import com.julewa.utils.ConfigUtils;

//used to load datas
public class Ibatis {
	
	private Map<String, BeanInfo> beans = null;
	private SqlMapClient sqlMap = null;
	private @Autowired TextsImpl texts;
	
	public Ibatis(){}
	
	private void init(){
		if(beans != null)return;
		Properties props = ConfigUtils.loadFullSystemConfig("ibatis.properties");
		if(props == null){
			props = ConfigUtils.loadFullSystemConfig("ibatis.conf");
		}
		IbatisLoader loader = new IbatisLoader(props, texts);
		sqlMap = loader.getSqlMapClient();
		beans = loader.getBeans();
	}

	public Map<String, BeanInfo> getBeans() {
		init();
		return beans;
	}

	public SqlMapClient getSqlMap() {
		init();
		return sqlMap;
	}
	
	
}
